﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace testSMS
{
    //BANG BAM CHO GO TV
    //Duoc xay dung boi : Nguyen Duy Phuong - Open University,
    // Email; duyphuong13@hotmail.com or hyesojong@yahoo.com
    public class Node
    {
        private char _first;
        private char _second;
        private string _kq;
        private Node _next;
        public char First
        {
            set { _first = value; }
            get { return _first; }
        }
        public char Second
        {
            set { _second = value; }
            get { return _second; }
        }
        public string KQ
        {
            set {_kq = value;}
            get {return _kq;}
        }
        public Node Next
        {
            set { _next = value; }
            get { return _next; }
        }

        public Node(char first, char second, string kq,Node next)
        {
            _first = first;
            _second = second;
            _kq = kq;
            _next = next;
        }
        public Node(char first, char second, string kq)
            :this(first,second,kq,null)
        { }

        public Node(Node next)
            : this(' ', ' ', "", next)
        { }
        public Node()
            : this(' ', ' ' , "", null)
        { }
       
    }

    public class BangBam
    {
        private Node[] heads = new Node[66];
        private Node z;
        private string _name;
        public BangBam(string name)
        {
            _name = name;
            z = new Node(z);
            for (int i = 0; i < 66; i++)
            {
                heads[i] = new Node(z);
            }
        }
        public BangBam()
            : this("Bang Bam")
        { }

        public void Them(char first, char second, string kq)
        {
            int key = first%'A';
            Node p, t, temp;
            t = heads[key];
            p = t.Next;
            
            // them dau` lun, khoi can loang ngoang :))
            temp = new Node(first, second, kq,p);
            t.Next = temp;
        }
        public string TimKiem(char first, char second)
        {
            
            int key = first % 'A';
            Node t = heads[key];
          

            do{
                // tim` tu dau` toi cuoi' lun, khoi can ktra, loang ngoang :))
                t= t.Next;
                if (t.First == first && t.Second == second) break;
            }while(t != z);

            if (t == z) return null;
            else return t.KQ;
           
        }
    }
}
